/**
 * 
 */
package com.regedit.aplicacion.communication;

import org.json.JSONObject;

import android.content.Context;
import android.content.res.Resources;

import com.regedit.aplicacion.R;

/**
 * @author pJohnson
 * 
 */
public class WebServiceConsumer {

	public static final boolean METHOD_GET = true;
	public static final boolean METHOD_POST = false;
	final private transient Context mContext;
	private transient String serverURL;
	private static WebServiceConsumer instance;
	private final Resources resources;

	/**
	 * Singleton method to get the instance of the class
	 * 
	 * @param mContext
	 *            the context
	 * @return the instance of the class
	 */
	public static WebServiceConsumer getInstance(final Context mContext) {
		if (instance == null) {
			instance = new WebServiceConsumer(mContext.getApplicationContext());
		}
		return instance;
	}

	private WebServiceConsumer(final Context context) {
		mContext = context;
		resources = this.mContext.getResources();
		serverURL = resources.getString(R.string.server);

	}

	
	public String getCarros() {
		final String urlToConsume = serverURL
				+ resources.getString(R.string.wsGetCarros);
		return RequestHttp.httpResponseString(urlToConsume, METHOD_GET,
				null);
	}

	public String insertAuto(JSONObject auto) {
		final String urlToConsume = serverURL
				+ resources.getString(R.string.wsInsertCarros);
		return RequestHttp.httpResponseString(urlToConsume, METHOD_POST, auto.toString());
	}

	
}
